package org.ilead.iserve.service.impl;

import java.util.List;

import org.ilead.iserve.dao.INewsDAO;
import org.ilead.iserve.model.News;
import org.ilead.iserve.service.INewsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NewsService implements INewsService {
	private static final Logger log = LoggerFactory
			.getLogger(NewsService.class);
	private INewsDAO newsDAO = null;
	
	
	public void setNewsDAO(INewsDAO newsDAO) {
		this.newsDAO = newsDAO;
	}
	@Override
	public List<News> findAll() {
		return newsDAO.findAll();
	}
	@Override
	public List<News> findByTitle(String title) {
		return newsDAO.findByTitle(title);
	}
	@Override
	public List<News> findByKeywords(String keywords) {
		return newsDAO.findByKeyWords(keywords);
	}
	@Override
	public List<News> findByCategroy(Integer cateId) {
		return newsDAO.findByCategoryId(cateId.longValue());
	}
	@Override
	public List<News> findByOperator(String oper) {
		return newsDAO.findByOperator(oper);
	}
	@Override
	public News findById(Integer id) {
		return newsDAO.findById(id.longValue());
	}
	@Override
	public void addNews(News n) throws Exception {
		newsDAO.save(n);	
	}
	@Override
	public void updateNews(News n) throws Exception {
		newsDAO.attachDirty(n);
		
	}
	@Override
	public void delNews(Integer id) throws Exception {
		newsDAO.delete(findById(id));		
	}

}
